import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class CommonPicker {
  static Future<int> showPicker({
    BuildContext context,
    List<String> options,
    int value=0,
    double height =300,
  }) {
    return showCupertinoModalPopup(
        context: context,
        builder: (BuildContext context) {
          var buttonTextStyle =TextStyle(
            color: Theme.of(context).primaryColor,
          fontSize: 16,
          fontWeight: FontWeight.w600,
          );
          return Container(
            color: Colors.grey,
            height: height,
            child: Column(
              children: <Widget>[
                Container(
                  color: Colors.grey[200],
                  height: 40,
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: <Widget>[
                      FlatButton(onPressed: () {Navigator.pop(context);}, child: Text("取消",style: buttonTextStyle,)),
                      FlatButton(onPressed: () {Navigator.of(context).pop(value);}, child: Text("确定",style: buttonTextStyle,)),
                    ],
                  ),
                ),
                Expanded(
                    child: CupertinoPicker(
                      scrollController: FixedExtentScrollController(initialItem: value),
                      backgroundColor: Colors.white,
                      //高度
                        itemExtent: 32,
                        onSelectedItemChanged:(val){
                          value =val;
                        },
                        children: options.map((item)=>Text(item)).toList())),
              ],
            ),
          );
        });
  }
}
